<template>
  <div class="jianjie">
        <div class="centent" v-for="(item,index) in content" :key="index">
          <p>{{item.title}}</p>

          <div class="centent-title">
              <p class="p1">{{item.categories[0].category_name}}-{{item.categories[0].sub.category_name}}</p>
              <p class="p1">{{kann[0]}}次播放</p>
          </div>

          <div class="centent-text">
              <p class="p2">{{item.content}}</p>
          </div>

          <div class="centent-icon">
              <div class="icon-item">
                <img src="../assets/点赞黑.png" alt="">
                <p class="pp">{{zann[0]}}</p>
              </div>
               <div class="icon-item">
                <img src="../assets/星星 .png" alt="">
                <p class="pp">{{cang}}</p>
              </div>
               <div class="icon-item">
                <img src="../assets/分享.png" alt="">
                <p class="pp">{{xiang}}</p>
              </div>
          </div>

          <div class="centent-bottom" >
             <div class="item" v-for="(item,index) in title" :key="index">{{item.name}}</div>
          </div>

          <div class="author">
              <p class="author-p">创作人</p>
              <div class="author-text">
                <div class="author-content">

                   <div class="author-item">
                       <img class="im1" :src="item.author.userinfo.avatar" alt="" @click="tiao(item.author.userinfo.id)">
                       <div class="author-name"  @click="tiao(item.author.userinfo.id)">
                           <span class="sp1">{{item.author.userinfo.username}}</span>
                           <img  class="im2" v-if="item.author.userinfo.vip_status===1" src="../assets/vip.png" alt="">
                           <span class="sp2">{{item.author.role}}</span>
                       </div>
                       <div class="guanzhu" :style="Guanstyle" @click="guan(item.author.userinfo.id)">{{guanzhu}}</div>
                   </div>
                
                </div>
              </div>
          </div>
       </div>

       <div class="xiangsi">
           <p>{{sititle}}</p>
           <div class="sicentent" v-for="(item,index) in xiangsivideo" :key="index" @click="xiangsi(item.id)">
               <img  :src="item.cover" alt="">
               <div class="centent-left">
                   <p class="p5">{{item.title}}</p>
                   <p class="p6">播放&nbsp;{{bofang[index]}}&nbsp;&nbsp;喜欢&nbsp;{{xihuan[index]}}</p>
                   <div class="authord">
                    <img class="imgauthor" :src="item.author.userinfo.avatar" alt="">
                   <span>{{item.author.userinfo.username}}</span>
                   </div>   
               </div>
           </div>
       </div>
  </div>
</template>

<script>
export default {
  created(){
    //   let ar = JSON.parse(localStorage.getItem("userid"));
    //   
    //   if(ar != null){
    //       for(let i = 0;i < ar.length; i++){
    //           this.authorid.unshift(ar[i]);
    //       }
    //   }
    //   
      this.getauthor(this.$route.query.id)
      
  },
  data(){
      return{
         content:[],
         //播放次数
         kann:[],
         //喜欢
         zann:[],
         //收藏
         cang:'',
         //分享
         xiang:'',
         //标题
         title:[],
         sititle:'',
         xiangsivideo:[],
         //推荐视频的播放
         bofang:[],
         //推荐视频的喜欢
         xihuan:[],
         id:'',
         //存储要关注用户的id
         authorid:[],
         //关注
         guanzhu:'关注',
         Guanstyle:{
              backgroundColor: 'rgb(250,237,231)',
              color: 'rgb(231,104,93)'
         },
         arr:[]
      }
  },
  methods:{
      //点击跳转用户页面
      tiao(id){
        this.$router.push({name:'author',query:{id:id}})
      },
      //视频详情页
      xiangsi(id){
       
          this.id=id
          this.$router.push({name:'jianjie',query:{id:id}})
          location.reload()
      },
      //关注
      guan(userid){
         this.guanzhu="已关注"
         this.Guanstyle.backgroundColor="#ddd"
         this.Guanstyle.color="white"
         this.myguanzhu(userid)
      },
      //视频点赞数
       formatNumber(num) {
      num = Number(num);
      if (num == 0) {
        return num + "";
      } else if (num >= 1 && num <= 10000) {
        return num + "";
      } else {
        return (num / 10000).toFixed(1) + "w";
      }
    },
      getauthor(id){
          this.axios({
              method:'get',
              url:'https://apis.netstart.cn/xpc/article/'+id
          }).then(result=>{
              this.content.push(result.data.data)
              
              this.title=this.content[0].tags
              this.content.forEach(v => {
                  let kan=this.formatNumber(v.count.count_view)
                  let zan=this.formatNumber(v.count.count_like)
                  let cang=this.formatNumber(v.count.count_collect)
                  let xiang=this.formatNumber(v.count.count_share)
                  this.cang=cang
                  this.xiang=xiang
                  this.kann.push(kan)
                  this.zann.push(zan)
              });
              this.getauthorleisi(this.$route.query.id)
              
          }).catch(err=>{
              
          })
      },

      //相似视频
      getauthorleisi(id){
         this.axios({
             method:'get',
             url:'https://apis.netstart.cn/xpc/article/'+id+'/next'
         }).then(result=>{
             
             this.sititle=result.data.data.title
             this.xiangsivideo=result.data.data.list
             this.xiangsivideo.forEach(v=>{
                let bofang=this.formatNumber(v.count.count_view)
                let xihuan=this.formatNumber(v.count.count_like)
                this.bofang.push(bofang)
                this.xihuan.push(xihuan)
                
             })
            
         }).catch(err=>{
            
         })
      },

      //设置本地存储用户的id
      myguanzhu(id){
         id=String(id)
         this.authorid.unshift(id)
         
        localStorage.setItem('userid',JSON.stringify(this.authorid))
      }
  }
}
</script>

<style lang="less" scoped>
.jianjie{
    width: 94%;
    padding: 10px;
    height: calc(100vh -264px);
    overflow-y: auto;
}
.centent{
    width: 100%;
    margin-top: -10px;
    p{
      width: 95%;
      margin-left: 10px;
      letter-spacing: 1px;
      font-size: 20px;
      font-weight: bold;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 1;
      overflow: hidden;
    }
    .centent-title{
        width: 70%;
        height: 30px;
       display: flex;
       margin-top: -10px;
       justify-content: space-between;
       .p1{
           height: 20px;
           margin-top: 0px;
           font-size: 13px;
           font-weight: 500;
           color: rgb(158, 157, 157);
           letter-spacing: 0px;
       }
    }
    .centent-text{
        width: 100%;
        margin-top: -15px;
        .p2{
            width: 95%;
            font-weight: 600;
            font-weight: 500;
            letter-spacing: 0px;
            font-size: 14px;
            color: rgb(138, 136, 136);
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 3;
            overflow: hidden;
        }
    }
    .centent-icon{
        width: 100%;
        height: 25px;
        display: flex;
        text-align: center;
        justify-content: space-between;
        .icon-item{
           width: 33%;
           height: 40px;
           text-align: center;
           
           img{
               width: 20px;
               height: 20px;
           }
           .pp{
               letter-spacing: 0px;
               display: flex;
               justify-content: center;
               width: 50%;
               margin-top: 0px;
               margin-left: 25%;
               font-size: 13px;
           }
        }
    
    }
    .centent-bottom{
        width: 100%;
        height: 80px;
        margin-top: 25px;
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        .item{
            padding: 5px;
            height: 20px;
            font-size: 12px;
            border-radius: 5px;
            margin-left: 15px;
            text-align: center;
            line-height: 20px;
            color: black;
            background-color: rgb(239, 237, 237);
        }
      
    }
    .author{
        width: 100%;
        height: 130px;
        .author-p{
           font-size: 18px;
           
        }
        .author-text{
            width: 100%;
            height: 70px;
           
            .author-content{
               height: 70px;
               white-space: nowrap;
               overflow-y: auto;
               .author-item{
                   width: 250px;
                   height: 70px;
                   display: flex;
                   display: inline-block;
                   border-radius: 10px;
                   border: 1px solid #ddd;
                   margin-left: 10px;
                   align-items: center;
                   box-shadow: 0px 0px 20px 0px #ddd;
                .im1{
                   width: 45px;
                   height: 45px;
                   border-radius: 50%;
                   margin-top: 10px;
                   border: 1px solid #ddd;
                }
                .author-name{
                    width: 45%;
                    height: 45px;
                    display: flex;
                    flex-wrap: wrap;
                    margin-top: -45px;
                    margin-left: 55px;
                    .sp1{
                        font-size: 13px;
                        letter-spacing: 1px;
                        font-weight: bold;
                        text-overflow: ellipsis;
                       display: -webkit-box;
                       -webkit-box-orient: vertical;
                       -webkit-line-clamp: 1;
                       overflow: hidden;
            
                    }
                    .im2{
                        width: 20px;
                        height: 20px;
                        margin-left: 5px;
                    }
                    .sp2{
                        width: 90%;
                        height: 20px;
                        font-size: 11px;
                        margin-top: 5px;
                        color: rgb(149, 145, 145);
                        text-overflow: ellipsis;
                       display: -webkit-box;
                       -webkit-box-orient: vertical;
                       -webkit-line-clamp: 1;
                       overflow: hidden;
                    }
                }
                .guanzhu{
                    margin-top: -40px;
                    margin-left:70%;
                    width: 70px;
                    height: 30px;
                    border-radius: 10px;
                    text-align: center;
                    line-height: 30px;
                    
                    
                    
                }
               }
            }
        }
    }
}
.xiangsi{
    width: 100%;
    p{
    width: 100%;
    height: 20px;
    font-size: 20px;
    font-weight: bold;
    margin-left: 10px;
    }
    .sicentent{
        width: 100%;
        height: 110px;
        display: flex;
        margin-bottom: 20px;
        img{
            width: 180px;
            height: 110px;
            border-radius: 10px;
        }
        .centent-left{
            width: 50%;
            height: 100px;
            .p5{
               text-overflow: ellipsis;
              display: -webkit-box;
              -webkit-box-orient: vertical;
              -webkit-line-clamp: 1;
              overflow: hidden;
              font-size: 15px;
            }
            .p6{
                margin-top: -3px;
                font-size: 12px;
                font-weight: 500;
                color: rgb(172, 168, 168);
            }
            .authord{
                display: flex;
                align-items: center;
                margin-top: -5px;
            }
            .imgauthor{
                width: 25px;
                height: 25px;
                border-radius: 50%;
                border: 1px solid #ddd;
                margin-left: 10px;
                margin-top: 0px;
            }
            span{
                margin-top: 0px;
                margin-left: 10px;
            }
        }
    }
   
}
</style>